package com.longqinuo.mycarservice.adapter;

import android.support.v4.app.FragmentTransaction;


import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.entity.AddGasStation;
import com.longqinuo.mycarservice.fragments.LookMapFragment;

import java.util.List;


/**
 * Created by zxw on 2016/5/24.
 */
public class AddGasStationAdapter extends RecyclerView.Adapter<AddGasStationAdapter.MyViewHolder>{
    private List<AddGasStation> mList;
    private int itemLayout;
    private FragmentTransaction mTransaction;
    public AddGasStationAdapter(List<AddGasStation> mList, int itemLayout, FragmentTransaction transaction) {
        this.mList = mList;
        this.itemLayout = itemLayout;
        this.mTransaction = transaction;
    }



    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(),itemLayout,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.lookMap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(holder.itemView.getContext(), "查看地图", Toast.LENGTH_SHORT).show();
                mTransaction.replace(R.id.ll_main_layout,new LookMapFragment(),"LookMap");
                mTransaction.addToBackStack("LookMap");
                mTransaction.commit();
            }
        });
        holder.serverPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(holder.itemView.getContext(), "客服电话", Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
            this.name = (TextView) itemView.findViewById(R.id.tv_name_add_gas);
            this.distance = (TextView) itemView.findViewById(R.id.tv_distance_add_gas);
            this.locale = (TextView) itemView.findViewById(R.id.tv_locale_add_gas);
            this.lookMap = (LinearLayout) itemView.findViewById(R.id.ll_look_map);
            this.serverPhone = (LinearLayout) itemView.findViewById(R.id.ll_server_phone);
        }

        public TextView name;
        public TextView distance;
        public TextView locale;
        public LinearLayout lookMap;
        public LinearLayout serverPhone;
    }
}

